package com.accounting.util;

import java.io.*;
import java.util.Properties;

public class ConfigManager {
    private static final String CONFIG_FILE = "config.properties";
    private static Properties properties;
    
    static {
        properties = new Properties();
        loadConfig();
    }
    
    private static void loadConfig() {
        try (InputStream input = new FileInputStream(CONFIG_FILE)) {
            properties.load(input);
        } catch (IOException e) {
            // 如果配置文件不存在，使用默认配置
            setDefaultConfig();
        }
    }
    
    private static void setDefaultConfig() {
        properties.setProperty("theme", "light");
        properties.setProperty("language", "zh_CN");
        saveConfig();
    }
    
    public static void saveConfig() {
        try (OutputStream output = new FileOutputStream(CONFIG_FILE)) {
            properties.store(output, "Application Configuration");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public static String getTheme() {
        return properties.getProperty("theme", "light");
    }
    
    public static void setTheme(String theme) {
        properties.setProperty("theme", theme);
        saveConfig();
    }
    
    public static String getLanguage() {
        return properties.getProperty("language", "zh_CN");
    }
    
    public static void setLanguage(String language) {
        properties.setProperty("language", language);
        saveConfig();
    }
} 